package fnord.jovian.tango;

import java.awt.*;
import java.awt.geom.*;

import fnord.illuminati.card.Alignment;
import fnord.illuminati.card.GroupCard;
import fnord.jovian.TheBoard;
import fnord.jovian.tango.TheAssemblyLayout.TheAssemblyOrientation;

public class TheTooltip extends ThePanel {

	public TheTooltip(TheBoard board, GroupCard card) {
		super(0,0,300,300,board);
		_shape = new RoundRectangle2D.Double(0,0,300,300,10,10);
		_background = new Color(150,150,150);
		_alpha = 0.5f;
		TheAssemblyLayout layout = new TheAssemblyLayout(TheAssemblyOrientation.VERTICAL, 30);
		setTheLayout(layout);
		if (card != null) {
			addComponent(new TheText(card.getName(),12,200,30,true,true));
			if (!card.getDescription().equals(""))
				addComponent(new TheText(card.getDescription(),10,200,40,true,false));
			addComponent(new TheStat("Power", card.getPower(), 200, true));
			addComponent(new TheStat("Transferable Power", card.getTransferablePower(), 200, true));
			addComponent(new TheStat("Resistance", card.getResistance(), 200, true));
			addComponent(new TheStat("Income", card.getIncome(), 200, true));
			addComponent(new TheStat("Money", card.getMoney(), 200, true));
			if (card.getAlignments().length > 0) {
				Alignment[] align = card.getAlignments();
				String alignments = "Alignments: " + align[0].toString();
				for (int i = 1; i < align.length; i++) {
					alignments += ", " + align[i].toString();
				}
				addComponent(new TheText(alignments, 12, 200, 40, true, false));
			}
		}

	}
	
	public void paint(Graphics2D g) {
		double height = _layout.getPadding()*2;
		for (int i = 0; i < _objects.size(); i++) {
			height += _objects.get(i).getHeight() + 10;
		}
		setSize(_shape.getWidth(), height);
		super.paint(g);
	}
	
	public void setLocation(double x, double y) {
		if (x + getWidth() > _board.getWidth())
			x = _board.getWidth() - getWidth();
		if (y + getHeight() > _board.getHeight())
			y = _board.getHeight() - getHeight();
		if (x < 0)
			x = 0;
		if (y < 0)
			y = 0;
		super.setLocation(x, y);
	}
	
}
